package com.ce.pms.report.service;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.ce.pms.report.dao.IReportDao;
import com.ce.pms.report.queryvo.AlreadyChargeItemListByTimeQueryVO;
import com.ce.pms.report.vo.AlreadyChargeItemListByTimeReportVO;
import com.ce.report.entity.CEReportDataSet;
import com.ce.report.exception.CEReportException;
import com.ce.report.service.ICEReportDataSetService;
import com.ce.report.vo.ReportsQueryBaseVo;
import com.ce.util.BlankUtil;
import com.ce.util.DateUtil;

/**
 *
 * 功能描述：财务已收款分项明细表(时间段)Service
 * <p>版权所有：中企动力
 * <p>未经本公司许可，不得以任何方式复制或使用本程序任何部分
 *
 * @author 黄彦军
 * Created on 2008-11-3
 * Edit author:
 * Edit on:
 * 修改原因:
 */
public class AlreadyChargeItemListByTimeService implements ICEReportDataSetService {

	private IReportDao reportDao;

	public CEReportDataSet getReportDataSet(ReportsQueryBaseVo arg0) throws CEReportException {
		AlreadyChargeItemListByTimeQueryVO queryVO = (AlreadyChargeItemListByTimeQueryVO) arg0;

		return new CEReportDataSet(getData(queryVO),getHeadInfo(queryVO));
	}

	/**
	 * 功能描述:获取数据  <br>
	 * @param queryVO
	 * @return
	 * Create author:黄彦军 <br>
	 * Create on:2008-11-14  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	private List<AlreadyChargeItemListByTimeReportVO> getData(AlreadyChargeItemListByTimeQueryVO queryVO){

		String precinct = queryVO.getPrecinct();
		String buildId = "";
		if (BlankUtil.isBlank(queryVO.getBuildingId())){
			buildId = "%";
		}else{
			buildId = queryVO.getBuildingId().toString();
		}


		String beginDate = DateUtil.convertDateToStr(queryVO.getBeginDate(), "yyyyMMdd");
		String endDate = DateUtil.convertDateToStr(queryVO.getEndDate(), "yyyyMMdd");
		Object[] obj = new Object[]{beginDate,endDate,buildId,precinct};

		List<Object[]> temp = reportDao.getDataList("alreadyChargeItemListByTime", obj);
		List<AlreadyChargeItemListByTimeReportVO> list = arrayToVO(temp);

		return list;
	}

	/**
	 * 功能描述: 财务已收款分项明细表(时间段) 对象数组 转 为VO 数组 <br>
	 *
	 * @param temp
	 * @return Create author:黄彦军 <br>
	 *         Create on:2008-11-7 <br>
	 *         Edit author: <br>
	 *         Edit on: <br>
	 *         Why: <br>
	 */
	private List<AlreadyChargeItemListByTimeReportVO> arrayToVO(
			List<Object[]> temp) {
		if (BlankUtil.isBlank(temp))
			return null;
		List<AlreadyChargeItemListByTimeReportVO> list = new ArrayList<AlreadyChargeItemListByTimeReportVO>();
		for (Object[] obj : temp) {
			AlreadyChargeItemListByTimeReportVO reportVO = new AlreadyChargeItemListByTimeReportVO();
			reportVO.setCompanyName((String) obj[0]);// 物业公司名称
			reportVO.setHouseNumber((String) obj[1]);// 房号
			reportVO.setUserName((String) obj[2]);// 客户名称
			reportVO.setAccounts((String) obj[3]);// 银行帐号
			reportVO.setComputeMonth((String) obj[4]);// 计费月份
			reportVO.setPayDate((Date) obj[5]);// 收费日期
			reportVO.setReceiptNO((String) obj[6]);// 单据号码
			reportVO.setActualPay((BigDecimal) obj[7]);// 实收金额
			reportVO.setLatefee((BigDecimal) obj[8]);// 滞纳金
			reportVO.setOverheadExpenses((BigDecimal) obj[9]);// 管理费
			reportVO.setOnticUpkeep((BigDecimal) obj[10]);// 本体维修金
			reportVO.setWaterPay((BigDecimal) obj[11]);// 水费
			reportVO.setElectricityPay((BigDecimal) obj[12]);// 电费
			reportVO.setSewagePay((BigDecimal) obj[13]);// 污水处理费
			reportVO.setGarbagePay((BigDecimal) obj[14]);// 垃圾处理费
			reportVO.setUpkeepPay((BigDecimal) obj[15]);// 维修费
			reportVO.setAdjustSum((BigDecimal) obj[16]);// 调整费用合计
			reportVO.setDerateSum((BigDecimal) obj[17]);// 减免费用合计
			list.add(reportVO);
		}
		return list;
	}

	/**
	 * 功能描述:获取头信息  <br>
	 * @param queryVO
	 * @return
	 * Create author:黄彦军 <br>
	 * Create on:2008-11-14  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	private Map<String, Object> getHeadInfo(AlreadyChargeItemListByTimeQueryVO queryVO){
		Map<String, Object> map =new HashMap<String, Object>();
		String beginDate = DateUtil.convertDateToStr(queryVO.getBeginDate(), "yyyy年MM月dd日");
		String endDate = DateUtil.convertDateToStr(queryVO.getEndDate(), "yyyy年MM月dd日");
		map.put("reportHeadStr", "统计时间:"+beginDate+"-"+endDate);
		map.put("printDate", new Date());

		return map;
	}

	public void setReportDao(IReportDao reportDao) {
		this.reportDao = reportDao;
	}
}
